import Mock from "mockjs";

// 创建数据
const { data } = Mock.mock({
  // 20条数据
  "data|52": [
    {
      // 工号
      "id|+1": /AC[0-9][0-9][1-9]$/,
      // 姓名
      name: "@cname",
      // 部门
      "branch|1": ["医师", "护士", "后勤"],
      // 应签到
      should: "09:00:00",
      // 实签到
      "sign|1": ["正常", "迟到"],
      // 应签退
      Should: "18:00:00",
      // 实签退
      "out|1": ["正常", "加班"],
      // 备注
      remarks: null,
    },
  ],
});

Mock.mock("/api/kaoqin/list","post",(options)=>{
    const {pageSize,currentPage,search}=JSON.parse(options.body);
    // console.log(data);
    
    if(pageSize&&currentPage){
      let result;
      let count=0;
      if(search){
       result = data.filter((item:any)=>item.id ===search)
       .slice((currentPage-1)*pageSize,currentPage*pageSize);
       count=data.filter((item:any)=>item.id ===search).length;
      }else{
         result = data.slice((currentPage-1)*pageSize,currentPage*pageSize);
         count=data.length;
      }
   
    
    return{
        status:0,
        result:result,
        count:count,
    };
    }else{
        return{
        status:1,
        result:"参数错误",
        }
    }
    
})


// 输出结果随机生成的数据（node index.js）
// console.log(data);

// export default data;
export default Mock;